package com.cheng.example.atguigu.view2.client27;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;


/**
 * lock加锁两次，只释放锁一次情况演示
 *
 * 这种情况程序基本就无限等待了
 * Reentrant可重入的意思
 */
public class Test03 {
    Lock lock = new ReentrantLock();

    public  void f1() {
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"\t"+"f1");
            f2();
        }finally {
            lock.unlock();
        }
    }

    public  void f2() {
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"\t"+"f3");
        }finally {
//            lock.unlock();
        }
    }

    public static void main(String[] args) {
        Test03 test03 = new Test03();

        new Thread(()->{
            test03.f1();
        },"t1").start();

        new Thread(()->{
            test03.f1();
        },"t2").start();

    }
}
